//
//  BigHeader.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/15.
//

#import "BigHeader.h"
#import "SDCycleScrollView.h"
#import <SDWebImage/SDWebImage.h>
@interface BigHeader()<SDCycleScrollViewDelegate>
@property(nonatomic,strong)UIImageView *bg;
@property(nonatomic,strong)UIImageView *logo;
@property(nonatomic,strong)UIImageView *user_icon;
@property(nonatomic,strong)UIImageView *tipImg;
@property(nonatomic,strong)UIImageView *apply;
@property(nonatomic,strong)UILabel *name;
@property(nonatomic,strong)UILabel *mLabel;
@property(nonatomic,strong)UIButton *banner;
@property(nonatomic,strong)UIImageView *titleImg;
@property(nonatomic,strong)UILabel *sLabel;
@property (nonatomic, strong)SDCycleScrollView *bannerView;
@property(nonatomic,strong)UIButton *leftService;
@property(nonatomic,strong)UIButton *rightService;
@property(nonatomic,strong)NSString *pid;
@property(nonatomic,strong)UILabel *applytext;
@property (nonatomic,strong)UILabel *t;
@property (nonatomic,strong)UILabel *t1;
@property (nonatomic,strong)UILabel *m;
@property (nonatomic,strong)UILabel *m1;

@end
@implementation BigHeader

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor =UIColor.clearColor;
        [self setUpUI];
    }
    return self;
}
-(void)setUpUI{
    [self addSubview:self.bg];
    [_bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_offset(0);
        make.height.mas_equalTo(424+MarginTop);
    }];
    [self addSubview:self.bannerView];
    [_bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_bg.mas_bottom).offset(10);
        make.left.mas_offset(13);
        make.right.mas_offset(-13);
        make.height.mas_equalTo(86);
    }];
//    [self addSubview:self.leftService];
//    [_leftService mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(_bannerView.mas_bottom).offset(28);
//        make.left.mas_offset(13);
//        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 36)/2, 93));
//    }];
//    [self addSubview:self.rightService];
//    [_rightService mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(_bannerView.mas_bottom).offset(28);
//        make.right.mas_offset(-13);
//        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 36)/2, 93));
//    }];
//    [self addSubview:self.titleImg];
//    [_titleImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(self);
//        make.top.equalTo(_leftService.mas_bottom).offset(20);
//    }];
//    [self addSubview:self.sLabel];
//    [_sLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(_titleImg.mas_bottom).offset(12);
//        make.width.mas_equalTo(SCREEN_WIDTH);
//    }];
//    [_leftService addTarget:self action:@selector(leftC) forControlEvents:UIControlEventTouchUpInside];
//    [_rightService addTarget:self action:@selector(rightC) forControlEvents:UIControlEventTouchUpInside];

}

-(void)leftC{
    if (self.leftrClick) {
        self.leftrClick();
    }
}

-(void)rightC{
    if (self.rightClick) {
        self.rightClick();
    }
}


-(UIImageView *)bg
{
    if(!_bg){
        _bg = [UIImageView new];
        _bg.userInteractionEnabled = YES;
        _bg.image = [UIImage imageNamed:@"home_big_bg"];
        _bg.contentMode = UIViewContentModeScaleToFill;
        [_bg addSubview:self.logo];
        [_logo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(MarginTop+20+10);
            make.left.mas_offset(13);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
        [_bg addSubview:self.name];
        [_name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(_logo);
            make.left.equalTo(_logo.mas_right).offset(5);
        }];
        CGFloat height = 0.0;
        if (@available(iOS 13.0, *)) {
            NSSet *set = [UIApplication sharedApplication].connectedScenes;
            UIWindowScene *windowScene = [set anyObject];
            UIStatusBarManager *statusBarManager = windowScene.statusBarManager;
            CGFloat topHeight = statusBarManager.statusBarFrame.size.height;
            height = topHeight ? topHeight : 20.0;
        }else {
            height = [[UIApplication sharedApplication] statusBarFrame].size.height;
        }
        UIView *view = [UIView new];
        [_bg addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_name.mas_bottom).offset(74);
            make.left.mas_offset(0);
            make.right.mas_offset(0);
            make.height.mas_equalTo(275);
        }];
        UIImageView *img = [UIImageView new];
        img.image = [UIImage imageNamed:@"home_big_midbg"];
        [view addSubview:img];
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_offset(0);
            make.left.mas_offset(14);
            make.right.mas_offset(-14);
        }];
        [view addSubview:self.mLabel];
        [_mLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.mas_equalTo(view);
            make.top.mas_offset(19);
            make.left.mas_offset(90);
        }];
        UILabel *l = [UILabel new];
        l.textColor = HexColor(@"#303030");
        l.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
        l.text = @"Loan amount(₱)";
        [view addSubview:l];
        [l mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_mLabel.mas_bottom).offset(12);
            make.left.mas_equalTo(_mLabel);
        }];
        [_bg addSubview:self.user_icon];
        [_user_icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_offset(-14);
            make.centerY.mas_equalTo(_logo);
        }];
//        [_bg addSubview:self.tipImg];
//        [_tipImg mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.bottom.mas_offset(0);
//            make.size.mas_equalTo(CGSizeMake(137, 172));
//        }];
        [view addSubview:self.t];
        [_t mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.mas_offset(28);
//            make.left.mas_offset(13);
            make.top.equalTo(l.mas_bottom).offset(50);
            make.left.mas_offset(70);
        }];
        [view addSubview:self.t1];
        [_t1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_t.mas_bottom).offset(5);
            make.centerX.mas_equalTo(_t);
        }];
        
        [view addSubview:self.m];
        [_m mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.mas_offset(80);
//            make.right.mas_offset(-25);
            make.top.equalTo(l.mas_bottom).offset(50);
            make.right.mas_offset(-70);
        }];
        [view addSubview:self.m1];
        [_m1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_m.mas_bottom).offset(5);
            make.centerX.mas_equalTo(_m);
        }];

        [view addSubview:self.applytext];
        [_applytext mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(view);
//            make.left.mas_offset(5);
            make.bottom.mas_offset(-20);
        }];
        [view addSubview:self.apply];
        [_apply mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.bottom.mas_offset(-10);
            make.size.mas_equalTo(CGSizeMake(15, 17));
            make.left.equalTo(_applytext.mas_right).offset(5);
            make.centerY.mas_equalTo(_applytext);
        }];

        
        UIButton *btn = [UIButton new];
        [view addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_offset(0);
        }];
        [btn addTarget:self action:@selector(applyClick:) forControlEvents:UIControlEventTouchUpInside];
        _user_icon.userInteractionEnabled = YES;
        UIButton *hbtn = [[UIButton alloc]init];
        [_user_icon addSubview:hbtn];
        [hbtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_offset(0);
        }];
        [_bg bringSubviewToFront:_user_icon];
        [hbtn addTarget:self action:@selector(headerClick1) forControlEvents:UIControlEventTouchUpInside];
    }
    return _bg;
}
-(void)headerClick1{
    if (self.headerClick) {
        self.headerClick();
    }
}
-(void)applyClick:(UIButton *)sender{
    if (self.applyAction) {
        self.applyAction(self.pid);
    }
}
-(UIImageView *)logo
{
    if(!_logo){
        _logo = [UIImageView new];
        _logo.image = [UIImage imageNamed:@"logo"];
        _logo.layer.cornerRadius = 5;
        _logo.layer.masksToBounds = YES;
        _logo.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _logo;
}
-(UIImageView *)user_icon{
    if(!_user_icon){
        _user_icon = [UIImageView new];
        _user_icon.image = [UIImage imageNamed:@"user"];
        _user_icon.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _user_icon;
}
-(UIImageView *)tipImg
{
    if(!_tipImg){
        _tipImg = [UIImageView new];
        _tipImg.image = [UIImage imageNamed:@"tips"];
        _tipImg.contentMode = UIViewContentModeScaleAspectFit;
        [_tipImg addSubview:self.t];
        [_t mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(28);
            make.left.mas_offset(13);
        }];
        [_tipImg addSubview:self.t1];
        [_t1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_t.mas_bottom).offset(0);
            make.centerX.mas_equalTo(_t);
        }];
        
        [_tipImg addSubview:self.m];
        [_m mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(80);
            make.right.mas_offset(-25);
        }];
        [_tipImg addSubview:self.m1];
        [_m1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_m.mas_bottom).offset(0);
            make.centerX.mas_equalTo(_m);
        }];

    }
    return _tipImg;
}
-(UIImageView *)apply
{
    if (!_apply) {
        _apply = [UIImageView new];
        _apply.image = [UIImage imageNamed:@"home_bg_apply"];
    }
    return _apply;
}
-(UILabel *)applytext
{
    if (!_applytext) {
        _applytext = [UILabel new];
        _applytext.textAlignment = NSTextAlignmentCenter;
        _applytext.textColor = HexColor(@"#ffffff");
        _applytext.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBold];
    }
    return _applytext;
}

-(UILabel *)mLabel
{
    if (!_mLabel) {
        _mLabel = [UILabel new];
//        _mLabel.text = @"₱ 80,000";
        _mLabel.textColor = HexColor(@"#333333");
        _mLabel.font = [UIFont systemFontOfSize:44 weight:UIFontWeightBold];
    }
    return _mLabel;
}
-(UIButton *)banner
{
    if (!_banner) {
        _banner = [UIButton buttonWithType:UIButtonTypeCustom];
        [_banner setImage:[UIImage imageNamed:@"banner"] forState:UIControlStateNormal];
    }
    return _banner;
}
-(UIImageView *)titleImg
{
    if(!_titleImg){
        _titleImg = [UIImageView new];
        _titleImg.image = [UIImage imageNamed:@"title"];
        _titleImg.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _titleImg;
}
-(UILabel *)sLabel
{
    if (!_sLabel) {
        _sLabel = [UILabel new];
        _sLabel.text = @"Compared with other lending platforms,\n we have six major advantages";
        _sLabel.textColor = DetailColor;
        _sLabel.numberOfLines = 2;
        _sLabel.textAlignment = NSTextAlignmentCenter;
        _sLabel.font = [UIFont systemFontOfSize:12];
    }
    return _sLabel;
}
-(SDCycleScrollView *)bannerView{
    if (!_bannerView) {
        //hd_pic_banner
        _bannerView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"home_big_banner"]];
        _bannerView.backgroundColor = UIColor.clearColor;
        _bannerView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
        _bannerView.autoScrollTimeInterval = 3;
        _bannerView.layer.cornerRadius = 16;
        _bannerView.layer.masksToBounds = YES;
        _bannerView.delegate = self;
    }
    return _bannerView;
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if (self.bannerClick) {
        self.bannerClick(index);
    }
}
-(UIButton *)leftService
{
    if (!_leftService) {
        _leftService = [UIButton buttonWithType:UIButtonTypeCustom];
        [_leftService setImage:[UIImage imageNamed:@"service"] forState:UIControlStateNormal];
    }
    return _leftService;
}
-(UIButton *)rightService
{
    if (!_rightService) {
        _rightService = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightService setImage:[UIImage imageNamed:@"service2"] forState:UIControlStateNormal];
    }
    return _rightService;
}
-(void)setSource:(NSDictionary *)source
{
    NSMutableArray *banners = [NSMutableArray array];
    NSArray *item = source[@"spokes"];
    [item enumerateObjectsUsingBlock:^(NSDictionary*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [banners addObject:obj[@"stringsha"]];
    }];
    _bannerView.imageURLStringsGroup = banners;
    

}
-(UILabel *)name
{
    if (!_name) {
        _name = [UILabel new];
        _name.font = [UIFont systemFontOfSize:30 weight:UIFontWeightBold];
        _name.textColor = HexColor(@"#FFFFFF");
    }
    return _name;
}

-(void)setItem:(NSDictionary *)item
{
    _t.text =item[@"spokes"][0][@"trouble"] ;
    _t1.text = item[@"spokes"][0][@"earthquake"] ;
    _m.text  = item[@"spokes"][0][@"remarkedive"] ;
    _m1.text = item[@"spokes"][0][@"toward"] ;
    _pid = [NSString stringWithFormat:@"%@",item[@"spokes"][0][@"adjadjadj"]];
    _mLabel.text = item[@"spokes"][0][@"voicethe"];
    [_logo sd_setImageWithURL:[NSURL URLWithString:CPS(item[@"spokes"][0][@"sorrow"])] placeholderImage:[UIImage imageNamed:@"logo"]];
    _name.text = CPS(item[@"spokes"][0][@"continued"]);
    _applytext.text = item[@"spokes"][0][@"deckwhat"];
}
-(UILabel *)t
{
    if (!_t) {
        _t = [UILabel new];
        _t.textColor = HexColor(@"#333333");
        _t.font  = [UIFont systemFontOfSize:14];
    }
    return _t;
}
-(UILabel *)t1
{
    if (!_t1) {
        _t1 = [UILabel new];
        _t1.textColor = HexColor(@"#333333");
        _t1.font  = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    }
    return _t1;
}
-(UILabel *)m{
    if (!_m) {
        _m = [UILabel new];
        _m.textColor = HexColor(@"#333333");
        _m.font  = [UIFont systemFontOfSize:14];
    }
    return _m;
}
-(UILabel *)m1
{
    if (!_m1) {
        _m1 = [UILabel new];
        _m1.textColor = HexColor(@"#333333");
        _m1.font  = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    }
    return _m1;
}
@end
